package com.aeert.streamquery.service.impl;

import com.aeert.streamquery.dao.ArticleDao;
import com.aeert.streamquery.entity.ArticleEntity;
import com.aeert.streamquery.service.ArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.cj.QueryResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.cursor.Cursor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Iterator;

/**
 * @Author zsj
 * @Description articleService
 * @Date 2020/12/22 下午7:57
 **/
@Service("articleService")
@Slf4j
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, ArticleEntity> implements ArticleService {


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void queryByCursor() {
        // try (Cursor<ArticleEntity> articleEntityCursor = baseMapper.select(articleEntityCursornull)) {
        try (Cursor<ArticleEntity> articleEntityCursor = baseMapper.queryByCursor()) {
            Iterator<ArticleEntity> articleEntityIterator = articleEntityCursor.iterator();
            while (articleEntityIterator.hasNext()) {
                log.debug("流式查询出参:{}",articleEntityIterator.next());
                // System.out.println(.getId());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
